package cn.toolck.minitomcat;

import cn.toolck.minitomcat.classLoader.MyClassLoader;
import cn.toolck.minitomcat.passer.ServerXmlPasser;
import cn.toolck.minitomcat.util.StaticResourceUtil;
import org.junit.Test;

import java.net.URL;

public class Mytest {
    @Test
    public void get() {
//        URL resource = Thread.currentThread().getContextClassLoader().getResource("");
//        System.out.println(resource.getPath() + "/index.html");
        int[] ints = {1, 2, 3, 3, 4, 4, 5, 6, 7, 9, 9, 9, 9, 9, 9, 10};
        getRe(ints);
    }
    @Test
    public void classLoaderTest() {
        MyClassLoader myClassLoader = new MyClassLoader("E:\\homework\\homework_02_01\\code\\mini_tomcat\\src\\main\\webapps\\web_demo\\WEB-INF\\classes");
        try {
            Class<?> aClass = myClassLoader.loadClass("cn.toolck.servlet.DemoServlet");
            System.out.println(aClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void passerTest(){
        ServerXmlPasser serverXmlPasser = new ServerXmlPasser("server.xml");
        serverXmlPasser.passFile();
    }

    private void getRe(int[] ints) {
        int length = ints.length;
        if (length <= 1) {
            if (length != 0) {
                System.out.println(ints[0]);
            }
            System.out.println(length);
        }

        Integer contNum = ints[0];
        int startIndex = 1;

        /*
         * 指针不停的向后走，
         * 使用contNum记录当前的数字（不重复的）
         * 如果当前数字小于等于contNum则为表示当前数字重复了
         *   endindex++
         * 如果当前数字大于contNum则为表示当前数字没有重复过
         *   此时将此index的数字与startIndex的数字交换位置，并将count ++ ,将此数字赋值与contNum
         *
         * */
        for (int endindex = 1; endindex < length; endindex++) {
            int anInt = ints[endindex];
            if (contNum < anInt) {
                contNum = anInt;
                ints[endindex] = ints[startIndex];
                ints[startIndex] = contNum;
                startIndex++;
            }
        }
        for (int i = 0; i < length; i++) {
            System.out.println(ints[i]);
        }
        System.out.println("=============================");
        System.out.println(startIndex);
    }
}
